package com.mdd.front.controller.yangyangLeadingEnterprise.index;

import com.mdd.common.aop.NotLogin;
import com.mdd.common.entity.yangyangLeadingEnterprise.TAppPolicyNews;
import com.mdd.common.entity.yangyangLeadingEnterprise.common.JsonReturn;
import com.mdd.common.entity.yangyangLeadingEnterprise.param.AppPolicyNewsParam;
import com.mdd.common.entity.yangyangLeadingEnterprise.param.CommonParam;
import com.mdd.front.service.yangyangLeadingEnterprise.ITAppPolicyNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("api.index/policyNews")
@Api(tags = "app首页---政策解读/政策新闻管理")
public class TAppPolicyNewsController {

    @Resource
    ITAppPolicyNewsService appPolicyNewsService;

    @NotLogin
    @PostMapping(value = "/selectList",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="app政策新闻列表")
    @ResponseBody
    public String selectList(@RequestBody AppPolicyNewsParam param) {
//        List<TAppPolicyNews> appPolicyNewsList = appPolicyNewsService.selectList(null,2,null,4);
        List<TAppPolicyNews> appPolicyNewsList = appPolicyNewsService.selectList(param);
        return JsonReturn.success().setListData(appPolicyNewsList).toJsonStr();
    }

    /**
     * 根据id查询政策新闻
     * @param param
     * @return
     */
    @NotLogin
    @PostMapping(value = "/selectById",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="根据id查询政策新闻")
    @ResponseBody
    public String selectById(@RequestBody CommonParam param) {
        Integer id = param.getId();
        if(id==null){
            return JsonReturn.fail("必传参数不能为空",40001).toJsonStr();
        }
        TAppPolicyNews appPolicyNews = appPolicyNewsService.selectById(id);
        if(appPolicyNews!=null && appPolicyNews.getId()!=null){
            //推荐其他的政策新闻
            AppPolicyNewsParam appPolicyNewsParam = new AppPolicyNewsParam();
            appPolicyNewsParam.setIdPks(Arrays.asList(appPolicyNews.getId()));
            appPolicyNewsParam.setAmount(2);
            List<TAppPolicyNews> appPolicyNewsList = appPolicyNewsService.selectList(appPolicyNewsParam);
            return JsonReturn.success().put("appPolicyNews",appPolicyNews).put("recommendAppPolicyNewsList",appPolicyNewsList).toJsonStr();
        }
        return JsonReturn.fail().toJsonStr();
    }



}
